package com.situ.Servlet.CokieSevlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieSevlet_2 extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Cookie[] cookies = req.getCookies();//从浏览器取得Cookis，放入数组遍历
		for (Cookie cookie : cookies) {
			if (cookie.getName().equals("goods")) {  //得到自己要的那个
				String value = cookie.getValue();  //找到名字匹配后，取出值
				System.out.println(value);
				PrintWriter writer = resp.getWriter();//打印页面
				writer.println(value);
			}
		}
	}
}